package binaryTree;

import java.util.ArrayList;
import java.util.List;

/**
 * 验证是否为二叉搜索树
 */
public class isBSFTree {
    public Boolean isValidBST(TreeNode root){
        List<Integer> list=new ArrayList<>();
        midTreave(root,list);
        for (int i=0;i<list.size()-1;i++){
            if (list.get(i+1)<=list.get(i)){
                return false;
            }
        }
        return true;
    }
    public static List<Integer> midTreave(TreeNode root,List<Integer> list){
        if (root==null){
            return null;
        }
        midTreave(root.left,list);
        list.add(root.val);
        midTreave(root.right,list);
        return list;
    }
}
